﻿//1184.公交站间的距离
int distanceBetweenBusStops(int* distance, int distanceSize, int start, int destination) {
    int R = 0;
    int L = 0;

    int i = start;
    while (i != destination)
    {
        L += distance[i];
        i = (i + 1) % distanceSize;
    }

    int j = destination;
    while (j != start)
    {
        R += distance[j];
        j = (j + 1) % distanceSize;
    }

    return R > L ? L : R;
}

//104.二叉树的最大深度
/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     struct TreeNode *left;
 *     struct TreeNode *right;
 * };
 */
int maxDepth(struct TreeNode* root) {
    if (root == NULL)
    {
        return 0;
    }
    int l = maxDepth(root->left) + 1;
    int r = maxDepth(root->right) + 1;
    return l > r ? l : r;
}

//111.二叉树的最小深度
/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     struct TreeNode *left;
 *     struct TreeNode *right;
 * };
 */
int minDepth(struct TreeNode* root) {
    if (root == NULL)
    {
        return 0;
    }
    if (root->left == NULL)
    {
        return minDepth(root->right) + 1;
    }
    if (root->right == NULL)
    {
        return minDepth(root->left) + 1;
    }
    return fmin(minDepth(root->left), minDepth(root->right)) + 1;
}